var inHoverMenu = false;

// make new menu

var makeMenuClicked = function () {
  var macroName = this.getAttribute('name');
  var url = '/make/new/' + macroName;
  showMask();
  $.get(url, {}, projectLoaded);
};

// load project
var projectLoaded = function (payload) {
  eval('var r = ' + payload + ';');
  $('.projectName').val(r.name);
  clearComponents();
  buildList(r.list);
  fillForm(r.current);
  hideMask();
  jq.hoverMenu.hide();
};

var buildList = function (components) {
  for (var i =0; i<components.length; i++) {
    var c = components[i];
    var jqElem = $(html.comList);
    jqElem.find('.title').html(c.title);
    jqElem.find('.title').attr('index', c.index);
    jqElem.find('.pages').html(c.pages);
    jq.list.append(jqElem);

    if (c.current) jqElem.addClass('current');
    events.registerComs();
  }
};

// register
events.loadProject = function () {
  jq.subMenu.find('li').click( makeMenuClicked );
};
